package com.hontech.pastacooking.conn

import com.hontech.pastacooking.app.await
import com.hontech.pastacooking.app.promise

class FramePromise (private val dest: Int,
                    private val req: Int) {

    private val promise = promise<Frame>()

    suspend fun await() = promise.await()
    suspend fun await(timeout: Long) = promise.await(timeout)

    fun complete(frame: Frame) {
        if ((frame.src == dest) && frame.request() == req) {
            promise.complete(frame)
        }
    }
}
